"""

 类成员参数传入装饰器的2种方法:
    1. 在装饰器的参数列表加入self;
    2. 在被修饰的方法外面再包一层方法, 并在末尾执行并返回被修饰方法;

"""

# @装饰器1
def on_startbuttons_clicked(flag):
    def pre_startwork(func):
        def startwork(self, *args, **kwargs):
            func(self, *args, **kwargs)
            print(self.myvalue)
            print('input arg is ' + flag)
        return startwork
    return pre_startwork

# @装饰器2
def on_endbuttons_clicked(flag):
    def pre_exitwork(func):
        def exitwork(*args, **kwargs):
            func(*args, **kwargs)
            print('exitflag=='+flag)
        return exitwork
    return pre_exitwork


class ShuoGG:
    def __init__(self):
        self.myvalue = '123'

    @on_startbuttons_clicked('shuoGG')
    def decorate_with_self(self):
        print('I am function in shuoGGClass')

    def wrapforself_myvalue(self):
        @on_endbuttons_clicked(self.myvalue)
        def Junction():
            print('I am wrapforself_myvalue in shuoGGClass')
        return Junction()


import time
def dotimes(func, times, interval):
    for x in range(0, times):
        if interval != 0:
            time.sleep(interval)
        func()

def do():
    exec('print(11111111)')

shuogg = ShuoGG()
shuogg.decorate_with_self()
shuogg.wrapforself_myvalue()
dotimes(do, 5, 0.5)